package cn.com.dhc.danlu.widget.home;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import java.util.List;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.util.CommonUtils;

/**
 * User: Geek_Soledad(wuhaiyang@danlu.com)
 * Date: 2016-08-01
 * Time: 13:55
 * Description: .....
 */
@Deprecated
public class PromotionsLayout extends RelativeLayout implements View.OnClickListener {
    public static final int THRESHOLD_PRO = 3;
    private RichTextView mRichTextView;

    private LinearLayout ll_fold;
    private ImageView iv_fold;

    private int mNormalColor;
    private int mHightLightColor ;
    private int mNormalSize;
    private int mHightLightSize;
    private int mRowSpace;
    public PromotionsLayout(Context context) {
        this(context, null);
    }
    public PromotionsLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public PromotionsLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.dl_promtion_richtext_style);
        mNormalColor = typedArray.getColor(R.styleable.dl_promtion_richtext_style_text_normal_color, Color.BLACK);
        mHightLightColor = typedArray.getColor(R.styleable.dl_promtion_richtext_style_text_highlight_color,Color.RED);
        mNormalSize = typedArray.getDimensionPixelSize(R.styleable.dl_promtion_richtext_style_text_normal_size, 12);
        mHightLightSize = typedArray.getDimensionPixelSize(R.styleable.dl_promtion_richtext_style_text_hightlight_size, 13);
        mRowSpace = typedArray.getDimensionPixelSize(R.styleable.dl_promtion_richtext_style_text_row_space,5);
        typedArray.recycle ();
        init();
    }
    private void init() {
        View.inflate(getContext(), R.layout.dl_promtion_layout, this);
        mRichTextView = (RichTextView) findViewById(R.id.tv_prompt);
        ll_fold = (LinearLayout) findViewById(R.id.ll_fold);
        iv_fold = (ImageView) findViewById(R.id.iv_fold);
        ll_fold.setOnClickListener(this);

        mRichTextView.bindAttr(mNormalColor, mHightLightColor, mNormalSize, mHightLightSize, mRowSpace);
    }
    @Override
    public void onClick(View v) {
        if (CommonUtils.isFastClick()) return;
        if (null != mOnFoldListener) {
            mOnFoldListener.onFoldAction(isFold());
        }
        mRichTextView.foldAction();
    }
    private boolean isFold(){
        return mRichTextView.isFold();
    }
    public void bindData(List datas, boolean isFold) {

        mRichTextView.bindData(datas, isFold);
        if (null != datas && datas.size() > THRESHOLD_PRO) {
            //计算 显示三条促销优惠消息 所占的高度
            ll_fold.setVisibility(VISIBLE);
        } else {
            ll_fold.setVisibility(GONE);
        }
    }
    private OnFoldListener mOnFoldListener;
    public void setOnFoldListener(OnFoldListener onFoldListener) {
        mOnFoldListener = onFoldListener;
    }
    public interface OnFoldListener {
        void onFoldAction(boolean fold);
    }
}
